<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Text::Template - Expand template text with embedded Perl - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Text-Template - MetaCPAN" href="https://metacpan.org/dist/Text-Template/releases.rss" />
        <link rel="canonical" href="./Text::Template.html" />
        <meta name="description" content="Expand template text with embedded Perl" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Text::Template" />
<meta name="twitter:title"       content="Text::Template" />
<meta name="twitter:description" content="Expand template text with embedded Perl" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Text::Template.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Text-Template was released.">
      <span class="relatize">28 Apr 2022 20:51:13 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Text-Template">Text-Template</a>
  </li>
  <li>
    Module version: 1.61
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Text-Template/source/lib/Text/Template.pm">Source</a>
    (<a href="https://metacpan.org/dist/Text-Template/source/lib/Text/Template.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Text-Template/source/lib/Text">Browse</a>
    (<a href="https://metacpan.org/dist/Text-Template/source/lib/Text?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Text-Template/changes">Changes</a>
    </li>
    <li>
      <a rel="noopener nofollow" class="nopopup" href="https://github.com/mschout/perl-text-template">Homepage</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Text-Template/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/mschout/perl-text-template">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/mschout/perl-text-template/issues">Issues</a>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Text-Template+1.61" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Template.html?oncpan=1&amp;distmat=1&amp;version=1.61&amp;grade=2" style="color: #090">4229</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Template.html?oncpan=1&amp;distmat=1&amp;version=1.61&amp;grade=3" style="color: #900">1</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/T/Text-Template.html?oncpan=1&amp;distmat=1&amp;version=1.61&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/MSCHOUT/Text-Template-1.61">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Text-Template who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 2
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Text-Template-1.61/index.html">93.32% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.8.0
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Text-Template/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/M/MS/MSCHOUT/Text-Template-1.61.tar.gz">
      Download (<span itemprop="fileSize">49.24KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FMSCHOUT%2FText-Template-1.61%2Flib%2FText%2FTemplate.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Text-Template/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Text-Template/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Text-Template">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Text-Template">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Text/Template.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="MSCHOUT/Text-Template-1.61"
>1.61
  (MSCHOUT on 2022-04-28)</option>
<option
  
  value="MSCHOUT/Text-Template-1.60"
>1.60
  (MSCHOUT on 2021-09-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.59"
>1.59
  (MSCHOUT on 2020-07-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.58"
>1.58
  (MSCHOUT on 2019-09-27)</option>
<option
  
  value="MSCHOUT/Text-Template-1.57"
>1.57
  (MSCHOUT on 2019-09-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.56"
>1.56
  (MSCHOUT on 2019-07-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.55"
>1.55
  (MSCHOUT on 2019-02-25)</option>
<option
  
  value="MSCHOUT/Text-Template-1.54"
>1.54
  (MSCHOUT on 2019-01-13)</option>
<option
  
  value="MSCHOUT/Text-Template-1.53"
>1.53
  (MSCHOUT on 2018-05-02)</option>
<option
  
  value="MSCHOUT/Text-Template-1.52"
>1.52
  (MSCHOUT on 2018-03-19)</option>
<option
  
  value="MSCHOUT/Text-Template-1.51"
>1.51
  (MSCHOUT on 2018-03-04)</option>
<option
  
  value="MSCHOUT/Text-Template-1.50"
>1.50
  (MSCHOUT on 2018-02-11)</option>
<option
  
  value="MSCHOUT/Text-Template-1.49"
>1.49
  (MSCHOUT on 2018-02-08)</option>
<option
  
  value="MSCHOUT/Text-Template-1.48"
>1.48
  (MSCHOUT on 2018-02-07)</option>
<option
  
  value="MSCHOUT/Text-Template-1.47"
>1.47
  (MSCHOUT on 2017-02-27)</option>
<option
  
  value="MJD/Text-Template-1.46"
>1.46
  (MJD on 2013-02-11)</option>
<option
  
  value="MJD/Text-Template-1.45"
>1.45
  (MJD on 2008-04-16)</option>
<option
  
  value="MJD/Text-Template-1.44"
>1.44
  (MJD on 2003-04-29)</option>
<option
  
  value="MJD/Text-Template-0.1b"
>0.1b
  (MJD on 1996-01-25)</option>
<option
  
  value="MJD/Text-Template-0.1a"
>0.1a
  (MJD on 1995-12-27)</option>
<optgroup label="BackPAN">'
<option
  
  value="ARISTOTLE/Text-Template-1.44"
>1.44
  (ARISTOTLE on 2018-02-25)</option>
<option
  
  value="MJD/Text-Template-1.43"
>1.43
  (MJD on 2002-03-25)</option>
<option
  
  value="MJD/Text-Template-1.42"
>1.42
  (MJD on 2001-11-05)</option>
<option
  
  value="MJD/Text-Template-1.41"
>1.41
  (MJD on 2001-09-04)</option>
<option
  
  value="MJD/Text-Template-1.40"
>1.40
  (MJD on 2001-08-30)</option>
<option
  
  value="MJD/Text-Template-1.31"
>1.31
  (MJD on 2001-02-05)</option>
<option
  
  value="MJD/Text-Template-1.23"
>1.23
  (MJD on 1999-12-21)</option>
<option
  
  value="MJD/Text-Template-1.20"
>1.20
  (MJD on 1999-03-08)</option>
<option
  
  value="MJD/Text-Template-1.12"
>1.12
  (MJD on 1999-02-28)</option>
<option
  
  value="MJD/Text-Template-1.11"
>1.11
  (MJD on 1999-02-25)</option>
<option
  
  value="MJD/Text-Template-1.10"
>1.10
  (MJD on 1999-02-13)</option>
<option
  
  value="MJD/Text-Template-1.03"
>1.03
  (MJD on 1999-02-06)</option>
<option
  
  value="MJD/Text-Template-1.0"
>1.0
  (MJD on 1999-02-05)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/MSCHOUT/Text-Template-1.61/diff/' + encodeURIComponent(this.value) + '/lib/Text/Template.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="MSCHOUT/Text-Template-1.61"
>1.61
  (MSCHOUT on 2022-04-28)</option>
<option
  
  value="MSCHOUT/Text-Template-1.60"
>1.60
  (MSCHOUT on 2021-09-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.59"
>1.59
  (MSCHOUT on 2020-07-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.58"
>1.58
  (MSCHOUT on 2019-09-27)</option>
<option
  
  value="MSCHOUT/Text-Template-1.57"
>1.57
  (MSCHOUT on 2019-09-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.56"
>1.56
  (MSCHOUT on 2019-07-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.55"
>1.55
  (MSCHOUT on 2019-02-25)</option>
<option
  
  value="MSCHOUT/Text-Template-1.54"
>1.54
  (MSCHOUT on 2019-01-13)</option>
<option
  
  value="MSCHOUT/Text-Template-1.53"
>1.53
  (MSCHOUT on 2018-05-02)</option>
<option
  
  value="MSCHOUT/Text-Template-1.52"
>1.52
  (MSCHOUT on 2018-03-19)</option>
<option
  
  value="MSCHOUT/Text-Template-1.51"
>1.51
  (MSCHOUT on 2018-03-04)</option>
<option
  
  value="MSCHOUT/Text-Template-1.50"
>1.50
  (MSCHOUT on 2018-02-11)</option>
<option
  
  value="MSCHOUT/Text-Template-1.49"
>1.49
  (MSCHOUT on 2018-02-08)</option>
<option
  
  value="MSCHOUT/Text-Template-1.48"
>1.48
  (MSCHOUT on 2018-02-07)</option>
<option
  
  value="MSCHOUT/Text-Template-1.47"
>1.47
  (MSCHOUT on 2017-02-27)</option>
<option
  
  value="MJD/Text-Template-1.46"
>1.46
  (MJD on 2013-02-11)</option>
<option
  
  value="MJD/Text-Template-1.45"
>1.45
  (MJD on 2008-04-16)</option>
<option
  
  value="MJD/Text-Template-1.44"
>1.44
  (MJD on 2003-04-29)</option>
<option
  
  value="MJD/Text-Template-0.1b"
>0.1b
  (MJD on 1996-01-25)</option>
<option
  
  value="MJD/Text-Template-0.1a"
>0.1a
  (MJD on 1995-12-27)</option>
<optgroup label="BackPAN">'
<option
  
  value="ARISTOTLE/Text-Template-1.44"
>1.44
  (ARISTOTLE on 2018-02-25)</option>
<option
  
  value="MJD/Text-Template-1.43"
>1.43
  (MJD on 2002-03-25)</option>
<option
  
  value="MJD/Text-Template-1.42"
>1.42
  (MJD on 2001-11-05)</option>
<option
  
  value="MJD/Text-Template-1.41"
>1.41
  (MJD on 2001-09-04)</option>
<option
  
  value="MJD/Text-Template-1.40"
>1.40
  (MJD on 2001-08-30)</option>
<option
  
  value="MJD/Text-Template-1.31"
>1.31
  (MJD on 2001-02-05)</option>
<option
  
  value="MJD/Text-Template-1.23"
>1.23
  (MJD on 1999-12-21)</option>
<option
  
  value="MJD/Text-Template-1.20"
>1.20
  (MJD on 1999-03-08)</option>
<option
  
  value="MJD/Text-Template-1.12"
>1.12
  (MJD on 1999-02-28)</option>
<option
  
  value="MJD/Text-Template-1.11"
>1.11
  (MJD on 1999-02-25)</option>
<option
  
  value="MJD/Text-Template-1.10"
>1.10
  (MJD on 1999-02-13)</option>
<option
  
  value="MJD/Text-Template-1.03"
>1.03
  (MJD on 1999-02-06)</option>
<option
  
  value="MJD/Text-Template-1.0"
>1.0
  (MJD on 1999-02-05)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Carp" title="Carp" class="ellipsis">Carp</a></li>
  <li><a href="https://metacpan.org/pod/Encode" title="Encode" class="ellipsis">Encode</a></li>
  <li><a href="https://metacpan.org/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li>
  <li><a href="https://metacpan.org/pod/base" title="base" class="ellipsis">base</a></li>
  <li><a href="https://metacpan.org/pod/strict" title="strict" class="ellipsis">strict</a></li>
  <li><a href="https://metacpan.org/pod/warnings" title="warnings" class="ellipsis">warnings</a></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Text::Template/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Text%3A%3ATemplate">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Text-Template">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/MSCHOUT/Text-Template-1.61/view/lib/Text/Template.pm">This version</a>
    </li>
    <li>
      <a href="./Text::Template.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/MJGARDNER"><img src="https://www.gravatar.com/avatar/6a6af58937682c4102ae0f02b2b8ff3d?d=identicon&amp;s=20" title="MJGARDNER" alt="MJGARDNER"></a>
<a class="display-all" href="https://metacpan.org/author/PABLROD"><img src="https://www.gravatar.com/avatar/ebde00b92598043f6cf8d9071e7d5c2b?d=identicon&amp;s=20" title="PABLROD" alt="PABLROD"></a>
<a class="display-all" href="https://metacpan.org/author/BRUNOV"><img src="https://www.gravatar.com/avatar/ff900b4f3eb6504c21691432e187923e?d=identicon&amp;s=20" title="BRUNOV" alt="BRUNOV"></a>
<a class="display-all" href="https://metacpan.org/author/ETHER"><img src="https://www.gravatar.com/avatar/bdc5cd06679e732e262f6c1b450a0237?d=identicon&amp;s=20" title="ETHER" alt="ETHER"></a>
<a class="display-all" href="https://metacpan.org/author/EBAUDREZ"><img src="https://www.gravatar.com/avatar/f9e9a154dc5f35342ed0a90e3e115548?d=identicon&amp;s=20" title="EBAUDREZ" alt="EBAUDREZ"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Text-Template/plussers">13 PAUSE users</a>
</div>
<div>
    10 non-PAUSE users
</div>
</div>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/MSCHOUT" class="author-name">Michael Schout</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Text/Template.pm&#39;" class="">
<option
  selected
  value="MSCHOUT/Text-Template-1.61"
>1.61
  (MSCHOUT on 2022-04-28)</option>
<option
  
  value="MSCHOUT/Text-Template-1.60"
>1.60
  (MSCHOUT on 2021-09-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.59"
>1.59
  (MSCHOUT on 2020-07-03)</option>
<option
  
  value="MSCHOUT/Text-Template-1.58"
>1.58
  (MSCHOUT on 2019-09-27)</option>
<option
  
  value="MSCHOUT/Text-Template-1.57"
>1.57
  (MSCHOUT on 2019-09-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.56"
>1.56
  (MSCHOUT on 2019-07-09)</option>
<option
  
  value="MSCHOUT/Text-Template-1.55"
>1.55
  (MSCHOUT on 2019-02-25)</option>
<option
  
  value="MSCHOUT/Text-Template-1.54"
>1.54
  (MSCHOUT on 2019-01-13)</option>
<option
  
  value="MSCHOUT/Text-Template-1.53"
>1.53
  (MSCHOUT on 2018-05-02)</option>
<option
  
  value="MSCHOUT/Text-Template-1.52"
>1.52
  (MSCHOUT on 2018-03-19)</option>
<option
  
  value="MSCHOUT/Text-Template-1.51"
>1.51
  (MSCHOUT on 2018-03-04)</option>
<option
  
  value="MSCHOUT/Text-Template-1.50"
>1.50
  (MSCHOUT on 2018-02-11)</option>
<option
  
  value="MSCHOUT/Text-Template-1.49"
>1.49
  (MSCHOUT on 2018-02-08)</option>
<option
  
  value="MSCHOUT/Text-Template-1.48"
>1.48
  (MSCHOUT on 2018-02-07)</option>
<option
  
  value="MSCHOUT/Text-Template-1.47"
>1.47
  (MSCHOUT on 2017-02-27)</option>
<option
  
  value="MJD/Text-Template-1.46"
>1.46
  (MJD on 2013-02-11)</option>
<option
  
  value="MJD/Text-Template-1.45"
>1.45
  (MJD on 2008-04-16)</option>
<option
  
  value="MJD/Text-Template-1.44"
>1.44
  (MJD on 2003-04-29)</option>
<option
  
  value="MJD/Text-Template-0.1b"
>0.1b
  (MJD on 1996-01-25)</option>
<option
  
  value="MJD/Text-Template-0.1a"
>0.1a
  (MJD on 1995-12-27)</option>
<optgroup label="BackPAN">'
<option
  
  value="ARISTOTLE/Text-Template-1.44"
>1.44
  (ARISTOTLE on 2018-02-25)</option>
<option
  
  value="MJD/Text-Template-1.43"
>1.43
  (MJD on 2002-03-25)</option>
<option
  
  value="MJD/Text-Template-1.42"
>1.42
  (MJD on 2001-11-05)</option>
<option
  
  value="MJD/Text-Template-1.41"
>1.41
  (MJD on 2001-09-04)</option>
<option
  
  value="MJD/Text-Template-1.40"
>1.40
  (MJD on 2001-08-30)</option>
<option
  
  value="MJD/Text-Template-1.31"
>1.31
  (MJD on 2001-02-05)</option>
<option
  
  value="MJD/Text-Template-1.23"
>1.23
  (MJD on 1999-12-21)</option>
<option
  
  value="MJD/Text-Template-1.20"
>1.20
  (MJD on 1999-03-08)</option>
<option
  
  value="MJD/Text-Template-1.12"
>1.12
  (MJD on 1999-02-28)</option>
<option
  
  value="MJD/Text-Template-1.11"
>1.11
  (MJD on 1999-02-25)</option>
<option
  
  value="MJD/Text-Template-1.10"
>1.10
  (MJD on 1999-02-13)</option>
<option
  
  value="MJD/Text-Template-1.03"
>1.03
  (MJD on 1999-02-06)</option>
<option
  
  value="MJD/Text-Template-1.0"
>1.0
  (MJD on 1999-02-05)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Text-Template">Text-Template-1.61</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage four &#10;
          • 66 direct dependents &#10;          • 1215 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="15"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Text-Template-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Text-Template-1.61">
    <input type="hidden" name="author" value="MSCHOUT">
    <input type="hidden" name="distribution" value="Text-Template">
    <button type="submit" class="favorite highlight"><span>23</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Text::Template.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>23</span> ++</a>
</div>
   / <span>Text::Template</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Text::Template.html#NAME">NAME</a></li>
  <li><a href="./Text::Template.html#VERSION">VERSION</a></li>
  <li><a href="./Text::Template.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Text::Template.html#DESCRIPTION">DESCRIPTION</a>
    <ul>
      <li><a href="./Text::Template.html#Example">Example</a></li>
      <li><a href="./Text::Template.html#Philosophy">Philosophy</a></li>
    </ul>
  </li>
  <li><a href="./Text::Template.html#Details">Details</a>
    <ul>
      <li><a href="./Text::Template.html#Template-Parsing">Template Parsing</a></li>
      <li><a href="./Text::Template.html#The-$OUT-variable">The $OUT variable</a></li>
      <li><a href="./Text::Template.html#General-Remarks">General Remarks</a></li>
      <li><a href="./Text::Template.html#new">new</a></li>
      <li><a href="./Text::Template.html#compile">compile</a></li>
      <li><a href="./Text::Template.html#fill_in">fill_in</a></li>
    </ul>
  </li>
  <li><a href="./Text::Template.html#Convenience-Functions">Convenience Functions</a>
    <ul>
      <li><a href="./Text::Template.html#fill_this_in">fill_this_in</a></li>
      <li><a href="./Text::Template.html#fill_in_string">fill_in_string</a></li>
      <li><a href="./Text::Template.html#fill_in_file">fill_in_file</a></li>
      <li><a href="./Text::Template.html#Including-files-into-templates">Including files into templates</a></li>
    </ul>
  </li>
  <li><a href="./Text::Template.html#Miscellaneous">Miscellaneous</a>
    <ul>
      <li><a href="./Text::Template.html#my-variables">my variables</a></li>
      <li><a href="./Text::Template.html#Security-Matters">Security Matters</a></li>
      <li><a href="./Text::Template.html#Alternative-Delimiters">Alternative Delimiters</a></li>
      <li><a href="./Text::Template.html#PREPEND-feature-and-using-strict-in-templates">PREPEND feature and using strict in templates</a></li>
      <li><a href="./Text::Template.html#Prepending-in-Derived-Classes">Prepending in Derived Classes</a></li>
      <li><a href="./Text::Template.html#JavaScript">JavaScript</a></li>
      <li><a href="./Text::Template.html#Compatibility">Compatibility</a></li>
      <li><a href="./Text::Template.html#Backslash-Processing">Backslash Processing</a></li>
      <li><a href="./Text::Template.html#A-short-note-about-$Text::Template::ERROR">A short note about $Text::Template::ERROR</a></li>
      <li><a href="./Text::Template.html#Sticky-Widgets-in-Template-Files">Sticky Widgets in Template Files</a></li>
      <li><a href="./Text::Template.html#Automatic-preprocessing-of-program-fragments">Automatic preprocessing of program fragments</a></li>
      <li><a href="./Text::Template.html#Automatic-postprocessing-of-template-hunks">Automatic postprocessing of template hunks</a></li>
    </ul>
  </li>
  <li><a href="./Text::Template.html#HISTORY">HISTORY</a></li>
  <li><a href="./Text::Template.html#THANKS">THANKS</a>
    <ul>
      <li><a href="./Text::Template.html#Bugs-and-Caveats">Bugs and Caveats</a></li>
    </ul>
  </li>
  <li><a href="./Text::Template.html#SOURCE">SOURCE</a></li>
  <li><a href="./Text::Template.html#BUGS">BUGS</a></li>
  <li><a href="./Text::Template.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Text::Template.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Text::Template - Expand template text with embedded Perl</p>

<h1 id="VERSION">VERSION</h1>

<p>version 1.61</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> use Text::Template;


 $template = Text::Template-&gt;new(TYPE =&gt; &#39;FILE&#39;,  SOURCE =&gt; &#39;filename.tmpl&#39;);
 $template = Text::Template-&gt;new(TYPE =&gt; &#39;ARRAY&#39;, SOURCE =&gt; [ ... ] );
 $template = Text::Template-&gt;new(TYPE =&gt; &#39;FILEHANDLE&#39;, SOURCE =&gt; $fh );
 $template = Text::Template-&gt;new(TYPE =&gt; &#39;STRING&#39;, SOURCE =&gt; &#39;...&#39; );
 $template = Text::Template-&gt;new(PREPEND =&gt; q{use strict;}, ...);

 # Use a different template file syntax:
 $template = Text::Template-&gt;new(DELIMITERS =&gt; [$open, $close], ...);

 $recipient = &#39;King&#39;;
 $text = $template-&gt;fill_in();  # Replaces `{$recipient}&#39; with `King&#39;
 print $text;

 $T::recipient = &#39;Josh&#39;;
 $text = $template-&gt;fill_in(PACKAGE =&gt; T);

 # Pass many variables explicitly
 $hash = { recipient =&gt; &#39;Abed-Nego&#39;,
           friends =&gt; [ &#39;me&#39;, &#39;you&#39; ],
           enemies =&gt; { loathsome =&gt; &#39;Saruman&#39;,
                        fearsome =&gt; &#39;Sauron&#39; },
         };
 $text = $template-&gt;fill_in(HASH =&gt; $hash, ...);
 # $recipient is Abed-Nego,
 # @friends is ( &#39;me&#39;, &#39;you&#39; ),
 # %enemies is ( loathsome =&gt; ..., fearsome =&gt; ... )


 # Call &amp;callback in case of programming errors in template
 $text = $template-&gt;fill_in(BROKEN =&gt; \&amp;callback, BROKEN_ARG =&gt; $ref, ...);

 # Evaluate program fragments in Safe compartment with restricted permissions
 $text = $template-&gt;fill_in(SAFE =&gt; $compartment, ...);

 # Print result text instead of returning it
 $success = $template-&gt;fill_in(OUTPUT =&gt; \*FILEHANDLE, ...);

 # Parse template with different template file syntax:
 $text = $template-&gt;fill_in(DELIMITERS =&gt; [$open, $close], ...);
 # Note that this is *faster* than using the default delimiters

 # Prepend specified perl code to each fragment before evaluating:
 $text = $template-&gt;fill_in(PREPEND =&gt; q{use strict &#39;vars&#39;;}, ...);

 use Text::Template &#39;fill_in_string&#39;;
 $text = fill_in_string( &lt;&lt;&#39;EOM&#39;, PACKAGE =&gt; &#39;T&#39;, ...);
 Dear {$recipient},
 Pay me at once.
        Love, 
         G.V.
 EOM

 use Text::Template &#39;fill_in_file&#39;;
 $text = fill_in_file($filename, ...);

 # All templates will always have `use strict vars&#39; attached to all fragments
 Text::Template-&gt;always_prepend(q{use strict &#39;vars&#39;;});</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This is a library for generating form letters, building HTML pages, or filling in templates generally. A `template&#39; is a piece of text that has little Perl programs embedded in it here and there. When you `fill in&#39; a template, you evaluate the little programs and replace them with their values.</p>

<p>You can store a template in a file outside your program. People can modify the template without modifying the program. You can separate the formatting details from the main code, and put the formatting parts of the program into the template. That prevents code bloat and encourages functional separation.</p>

<h2 id="Example">Example</h2>

<p>Here&#39;s an example of a template, which we&#39;ll suppose is stored in the file <code>formletter.tmpl</code>:</p>

<pre><code>    Dear {$title} {$lastname},

    It has come to our attention that you are delinquent in your
    {$monthname[$last_paid_month]} payment.  Please remit
    ${sprintf(&quot;%.2f&quot;, $amount)} immediately, or your patellae may
    be needlessly endangered.

                    Love,

                    Mark &quot;Vizopteryx&quot; Dominus</code></pre>

<p>The result of filling in this template is a string, which might look something like this:</p>

<pre><code>    Dear Mr. Smith,

    It has come to our attention that you are delinquent in your
    February payment.  Please remit
    $392.12 immediately, or your patellae may
    be needlessly endangered.


                    Love,

                    Mark &quot;Vizopteryx&quot; Dominus</code></pre>

<p>Here is a complete program that transforms the example template into the example result, and prints it out:</p>

<pre><code>    use Text::Template;

    my $template = Text::Template-&gt;new(SOURCE =&gt; &#39;formletter.tmpl&#39;)
      or die &quot;Couldn&#39;t construct template: $Text::Template::ERROR&quot;;

    my @monthname = qw(January February March April May June
                       July August September October November December);
    my %vars = (title           =&gt; &#39;Mr.&#39;,
                firstname       =&gt; &#39;John&#39;,
                lastname        =&gt; &#39;Smith&#39;,
                last_paid_month =&gt; 1,   # February
                amount          =&gt; 392.12,
                monthname       =&gt; \@monthname);

    my $result = $template-&gt;fill_in(HASH =&gt; \%vars);

    if (defined $result) { print $result }
    else { die &quot;Couldn&#39;t fill in template: $Text::Template::ERROR&quot; }</code></pre>

<h2 id="Philosophy">Philosophy</h2>

<p>When people make a template module like this one, they almost always start by inventing a special syntax for substitutions. For example, they build it so that a string like <code>%%VAR%%</code> is replaced with the value of <code>$VAR</code>. Then they realize the need extra formatting, so they put in some special syntax for formatting. Then they need a loop, so they invent a loop syntax. Pretty soon they have a new little template language.</p>

<p>This approach has two problems: First, their little language is crippled. If you need to do something the author hasn&#39;t thought of, you lose. Second: Who wants to learn another language? You already know Perl, so why not use it?</p>

<p><code>Text::Template</code> templates are programmed in <i>Perl</i>. You embed Perl code in your template, with <code>{</code> at the beginning and <code>}</code> at the end. If you want a variable interpolated, you write it the way you would in Perl. If you need to make a loop, you can use any of the Perl loop constructions. All the Perl built-in functions are available.</p>

<h1 id="Details">Details</h1>

<h2 id="Template-Parsing"><a id="Template"></a>Template Parsing</h2>

<p>The <code>Text::Template</code> module scans the template source. An open brace <code>{</code> begins a program fragment, which continues until the matching close brace <code>}</code>. When the template is filled in, the program fragments are evaluated, and each one is replaced with the resulting value to yield the text that is returned.</p>

<p>A backslash <code>\</code> in front of a brace (or another backslash that is in front of a brace) escapes its special meaning. The result of filling out this template:</p>

<pre><code>    \{ The sum of 1 and 2 is {1+2}  \}</code></pre>

<p>is</p>

<pre><code>    { The sum of 1 and 2 is 3  }</code></pre>

<p>If you have an unmatched brace, <code>Text::Template</code> will return a failure code and a warning about where the problem is. Backslashes that do not precede a brace are passed through unchanged. If you have a template like this:</p>

<pre><code>    { &quot;String that ends in a newline.\n&quot; }</code></pre>

<p>The backslash inside the string is passed through to Perl unchanged, so the <code>\n</code> really does turn into a newline. See the note at the end for details about the way backslashes work. Backslash processing is <i>not</i> done when you specify alternative delimiters with the <code>DELIMITERS</code> option. (See <a href="./Text::Template.html#Alternative-Delimiters">&quot;Alternative Delimiters&quot;</a>, below.)</p>

<p>Each program fragment should be a sequence of Perl statements, which are evaluated the usual way. The result of the last statement executed will be evaluated in scalar context; the result of this statement is a string, which is interpolated into the template in place of the program fragment itself.</p>

<p>The fragments are evaluated in order, and side effects from earlier fragments will persist into later fragments:</p>

<pre><code>    {$x = @things; &#39;&#39;}The Lord High Chamberlain has gotten {$x}
    things for me this year.
    { $diff = $x - 17;
      $more = &#39;more&#39;
      if ($diff == 0) {
        $diff = &#39;no&#39;;
      } elsif ($diff &lt; 0) {
        $more = &#39;fewer&#39;;
      }
      &#39;&#39;;
    }
    That is {$diff} {$more} than he gave me last year.</code></pre>

<p>The value of <code>$x</code> set in the first line will persist into the next fragment that begins on the third line, and the values of <code>$diff</code> and <code>$more</code> set in the second fragment will persist and be interpolated into the last line. The output will look something like this:</p>

<pre><code>    The Lord High Chamberlain has gotten 42
    things for me this year.

    That is 25 more than he gave me last year.</code></pre>

<p>That is all the syntax there is.</p>

<h2 id="The-$OUT-variable"><a id="The"></a><a id="The--OUT-variable"></a>The <code>$OUT</code> variable</h2>

<p>There is one special trick you can play in a template. Here is the motivation for it: Suppose you are going to pass an array, <code>@items</code>, into the template, and you want the template to generate a bulleted list with a header, like this:</p>

<pre><code>    Here is a list of the things I have got for you since 1907:
      * Ivory
      * Apes
      * Peacocks
      * ...</code></pre>

<p>One way to do it is with a template like this:</p>

<pre><code>    Here is a list of the things I have got for you since 1907:
    { my $blist = &#39;&#39;;
      foreach $i (@items) {
          $blist .= qq{  * $i\n};
      }
      $blist;
    }</code></pre>

<p>Here we construct the list in a variable called <code>$blist</code>, which we return at the end. This is a little cumbersome. There is a shortcut.</p>

<p>Inside of templates, there is a special variable called <code>$OUT</code>. Anything you append to this variable will appear in the output of the template. Also, if you use <code>$OUT</code> in a program fragment, the normal behavior, of replacing the fragment with its return value, is disabled; instead the fragment is replaced with the value of <code>$OUT</code>. This means that you can write the template above like this:</p>

<pre><code>    Here is a list of the things I have got for you since 1907:
    { foreach $i (@items) {
        $OUT .= &quot;  * $i\n&quot;;
      }
    }</code></pre>

<p><code>$OUT</code> is reinitialized to the empty string at the start of each program fragment. It is private to <code>Text::Template</code>, so you can&#39;t use a variable named <code>$OUT</code> in your template without invoking the special behavior.</p>

<h2 id="General-Remarks"><a id="General"></a>General Remarks</h2>

<p>All <code>Text::Template</code> functions return <code>undef</code> on failure, and set the variable <code>$Text::Template::ERROR</code> to contain an explanation of what went wrong. For example, if you try to create a template from a file that does not exist, <code>$Text::Template::ERROR</code> will contain something like:</p>

<pre><code>    Couldn&#39;t open file xyz.tmpl: No such file or directory</code></pre>

<h2 id="new"><code>new</code></h2>

<pre><code>    $template = Text::Template-&gt;new( TYPE =&gt; ..., SOURCE =&gt; ... );</code></pre>

<p>This creates and returns a new template object. <code>new</code> returns <code>undef</code> and sets <code>$Text::Template::ERROR</code> if it can&#39;t create the template object. <code>SOURCE</code> says where the template source code will come from. <code>TYPE</code> says what kind of object the source is.</p>

<p>The most common type of source is a file:</p>

<pre><code>    Text::Template-&gt;new( TYPE =&gt; &#39;FILE&#39;, SOURCE =&gt; $filename );</code></pre>

<p>This reads the template from the specified file. The filename is opened with the Perl <code>open</code> command, so it can be a pipe or anything else that makes sense with <code>open</code>.</p>

<p>The <code>TYPE</code> can also be <code>STRING</code>, in which case the <code>SOURCE</code> should be a string:</p>

<pre><code>    Text::Template-&gt;new( TYPE =&gt; &#39;STRING&#39;,
                         SOURCE =&gt; &quot;This is the actual template!&quot; );</code></pre>

<p>The <code>TYPE</code> can be <code>ARRAY</code>, in which case the source should be a reference to an array of strings. The concatenation of these strings is the template:</p>

<pre><code>    Text::Template-&gt;new( TYPE =&gt; &#39;ARRAY&#39;,
                             SOURCE =&gt; [ &quot;This is &quot;, &quot;the actual&quot;,
                                         &quot; template!&quot;,
                                       ]
                       );</code></pre>

<p>The <code>TYPE</code> can be FILEHANDLE, in which case the source should be an open filehandle (such as you got from the <code>FileHandle</code> or <code>IO::*</code> packages, or a glob, or a reference to a glob). In this case <code>Text::Template</code> will read the text from the filehandle up to end-of-file, and that text is the template:</p>

<pre><code>    # Read template source code from STDIN:
    Text::Template-&gt;new ( TYPE =&gt; &#39;FILEHANDLE&#39;, 
                          SOURCE =&gt; \*STDIN  );</code></pre>

<p>If you omit the <code>TYPE</code> attribute, it&#39;s taken to be <code>FILE</code>. <code>SOURCE</code> is required. If you omit it, the program will abort.</p>

<p>The words <code>TYPE</code> and <code>SOURCE</code> can be spelled any of the following ways:</p>

<pre><code>    TYPE     SOURCE
    Type     Source
    type     source
    -TYPE    -SOURCE
    -Type    -Source
    -type    -source</code></pre>

<p>Pick a style you like and stick with it.</p>

<dl>

<dt id="DELIMITERS"><code>DELIMITERS</code></dt>
<dd>

<p>You may also add a <code>DELIMITERS</code> option. If this option is present, its value should be a reference to an array of two strings. The first string is the string that signals the beginning of each program fragment, and the second string is the string that signals the end of each program fragment. See <a href="./Text::Template.html#Alternative-Delimiters">&quot;Alternative Delimiters&quot;</a>, below.</p>

</dd>
<dt id="ENCODING"><code>ENCODING</code></dt>
<dd>

<p>You may also add a <code>ENCODING</code> option. If this option is present, and the <code>SOURCE</code> is a <code>FILE</code>, then the data will be decoded from the given encoding using the <a href="https://metacpan.org/pod/Encode">Encode</a> module. You can use any encoding that <a href="https://metacpan.org/pod/Encode">Encode</a> recognizes. E.g.:</p>

<pre><code>    Text::Template-&gt;new(
        TYPE     =&gt; &#39;FILE&#39;,
        ENCODING =&gt; &#39;UTF-8&#39;,
        SOURCE   =&gt; &#39;xyz.tmpl&#39;);</code></pre>

</dd>
<dt id="UNTAINT"><code>UNTAINT</code></dt>
<dd>

<p>If your program is running in taint mode, you may have problems if your templates are stored in files. Data read from files is considered &#39;untrustworthy&#39;, and taint mode will not allow you to evaluate the Perl code in the file. (It is afraid that a malicious person might have tampered with the file.)</p>

<p>In some environments, however, local files are trustworthy. You can tell <code>Text::Template</code> that a certain file is trustworthy by supplying <code>UNTAINT =&gt; 1</code> in the call to <code>new</code>. This will tell <code>Text::Template</code> to disable taint checks on template code that has come from a file, as long as the filename itself is considered trustworthy. It will also disable taint checks on template code that comes from a filehandle. When used with <code>TYPE =&gt; &#39;string&#39;</code> or <code>TYPE =&gt; &#39;array&#39;</code>, it has no effect.</p>

<p>See <a href="https://metacpan.org/pod/perlsec">perlsec</a> for more complete information about tainting.</p>

<p>Thanks to Steve Palincsar, Gerard Vreeswijk, and Dr. Christoph Baehr for help with this feature.</p>

</dd>
<dt id="PREPEND"><code>PREPEND</code></dt>
<dd>

<p>This option is passed along to the <code>fill_in</code> call unless it is overridden in the arguments to <code>fill_in</code>. See <a href="https://metacpan.org/pod/PREPEND"><code>PREPEND</code></a> feature and using <code>strict</code> in templates&gt; below.</p>

</dd>
<dt id="BROKEN"><code>BROKEN</code></dt>
<dd>

<p>This option is passed along to the <code>fill_in</code> call unless it is overridden in the arguments to <code>fill_in</code>. See <a href="https://metacpan.org/pod/BROKEN"><code>BROKEN</code></a> below.</p>

</dd>
</dl>

<h2 id="compile"><code>compile</code></h2>

<pre><code>    $template-&gt;compile()</code></pre>

<p>Loads all the template text from the template&#39;s source, parses and compiles it. If successful, returns true; otherwise returns false and sets <code>$Text::Template::ERROR</code>. If the template is already compiled, it returns true and does nothing.</p>

<p>You don&#39;t usually need to invoke this function, because <code>fill_in</code> (see below) compiles the template if it isn&#39;t compiled already.</p>

<p>If there is an argument to this function, it must be a reference to an array containing alternative delimiter strings. See <code>&quot;Alternative Delimiters&quot;</code>, below.</p>

<h2 id="fill_in"><code>fill_in</code></h2>

<pre><code>    $template-&gt;fill_in(OPTIONS);</code></pre>

<p>Fills in a template. Returns the resulting text if successful. Otherwise, returns <code>undef</code> and sets <code>$Text::Template::ERROR</code>.</p>

<p>The <i>OPTIONS</i> are a hash, or a list of key-value pairs. You can write the key names in any of the six usual styles as above; this means that where this manual says <code>PACKAGE</code> (for example) you can actually use any of</p>

<pre><code>    PACKAGE Package package -PACKAGE -Package -package</code></pre>

<p>Pick a style you like and stick with it. The all-lowercase versions may yield spurious warnings about</p>

<pre><code>    Ambiguous use of package =&gt; resolved to &quot;package&quot;</code></pre>

<p>so you might like to avoid them and use the capitalized versions.</p>

<p>At present, there are eight legal options: <code>PACKAGE</code>, <code>BROKEN</code>, <code>BROKEN_ARG</code>, <code>FILENAME</code>, <code>SAFE</code>, <code>HASH</code>, <code>OUTPUT</code>, and <code>DELIMITERS</code>.</p>

<dl>

<dt id="PACKAGE"><code>PACKAGE</code></dt>
<dd>

<p><code>PACKAGE</code> specifies the name of a package in which the program fragments should be evaluated. The default is to use the package from which <code>fill_in</code> was called. For example, consider this template:</p>

<pre><code>    The value of the variable x is {$x}.</code></pre>

<p>If you use <code>$template-&gt;fill_in(PACKAGE =&gt; &#39;R&#39;)</code> , then the <code>$x</code> in the template is actually replaced with the value of <code>$R::x</code>. If you omit the <code>PACKAGE</code> option, <code>$x</code> will be replaced with the value of the <code>$x</code> variable in the package that actually called <code>fill_in</code>.</p>

<p>You should almost always use <code>PACKAGE</code>. If you don&#39;t, and your template makes changes to variables, those changes will be propagated back into the main program. Evaluating the template in a private package helps prevent this. The template can still modify variables in your program if it wants to, but it will have to do so explicitly. See the section at the end on `Security&#39;.</p>

<p>Here&#39;s an example of using <code>PACKAGE</code>:</p>

<pre><code>    Your Royal Highness,

    Enclosed please find a list of things I have gotten
    for you since 1907:

    { foreach $item (@items) {
            $item_no++;
        $OUT .= &quot; $item_no. \u$item\n&quot;;
      }
    }

    Signed,
    Lord High Chamberlain</code></pre>

<p>We want to pass in an array which will be assigned to the array <code>@items</code>. Here&#39;s how to do that:</p>

<pre><code>    @items = (&#39;ivory&#39;, &#39;apes&#39;, &#39;peacocks&#39;, );
    $template-&gt;fill_in();</code></pre>

<p>This is not very safe. The reason this isn&#39;t as safe is that if you had a variable named <code>$item_no</code> in scope in your program at the point you called <code>fill_in</code>, its value would be clobbered by the act of filling out the template. The problem is the same as if you had written a subroutine that used those variables in the same way that the template does. (<code>$OUT</code> is special in templates and is always safe.)</p>

<p>One solution to this is to make the <code>$item_no</code> variable private to the template by declaring it with <code>my</code>. If the template does this, you are safe.</p>

<p>But if you use the <code>PACKAGE</code> option, you will probably be safe even if the template does <i>not</i> declare its variables with <code>my</code>:</p>

<pre><code>    @Q::items = (&#39;ivory&#39;, &#39;apes&#39;, &#39;peacocks&#39;, );
    $template-&gt;fill_in(PACKAGE =&gt; &#39;Q&#39;);</code></pre>

<p>In this case the template will clobber the variable <code>$Q::item_no</code>, which is not related to the one your program was using.</p>

<p>Templates cannot affect variables in the main program that are declared with <code>my</code>, unless you give the template references to those variables.</p>

</dd>
<dt id="HASH"><code>HASH</code></dt>
<dd>

<p>You may not want to put the template variables into a package. Packages can be hard to manage: You can&#39;t copy them, for example. <code>HASH</code> provides an alternative.</p>

<p>The value for <code>HASH</code> should be a reference to a hash that maps variable names to values. For example,</p>

<pre><code>    $template-&gt;fill_in(
        HASH =&gt; {
            recipient =&gt; &quot;The King&quot;,
            items     =&gt; [&#39;gold&#39;, &#39;frankincense&#39;, &#39;myrrh&#39;],
            object    =&gt; \$self,
        }
    );</code></pre>

<p>will fill out the template and use <code>&quot;The King&quot;</code> as the value of <code>$recipient</code> and the list of items as the value of <code>@items</code>. Note that we pass an array reference, but inside the template it appears as an array. In general, anything other than a simple string or number should be passed by reference.</p>

<p>We also want to pass an object, which is in <code>$self</code>; note that we pass a reference to the object, <code>\$self</code> instead. Since we&#39;ve passed a reference to a scalar, inside the template the object appears as <code>$object</code>.</p>

<p>The full details of how it works are a little involved, so you might want to skip to the next section.</p>

<p>Suppose the key in the hash is <i>key</i> and the value is <i>value</i>.</p>

<ul>

<li><p>If the <i>value</i> is <code>undef</code>, then any variables named <code>$key</code>, <code>@key</code>, <code>%key</code>, etc., are undefined.</p>

</li>
<li><p>If the <i>value</i> is a string or a number, then <code>$key</code> is set to that value in the template.</p>

</li>
<li><p>For anything else, you must pass a reference.</p>

<p>If the <i>value</i> is a reference to an array, then <code>@key</code> is set to that array. If the <i>value</i> is a reference to a hash, then <code>%key</code> is set to that hash. Similarly if <i>value</i> is any other kind of reference. This means that</p>

<pre><code>    var =&gt; &quot;foo&quot;</code></pre>

<p>and</p>

<pre><code>    var =&gt; \&quot;foo&quot;</code></pre>

<p>have almost exactly the same effect. (The difference is that in the former case, the value is copied, and in the latter case it is aliased.)</p>

</li>
<li><p>In particular, if you want the template to get an object or any kind, you must pass a reference to it:</p>

<pre><code>    $template-&gt;fill_in(HASH =&gt; { database_handle =&gt; \$dbh, ... });</code></pre>

<p>If you do this, the template will have a variable <code>$database_handle</code> which is the database handle object. If you leave out the <code>\</code>, the template will have a hash <code>%database_handle</code>, which exposes the internal structure of the database handle object; you don&#39;t want that.</p>

</li>
</ul>

<p>Normally, the way this works is by allocating a private package, loading all the variables into the package, and then filling out the template as if you had specified that package. A new package is allocated each time. However, if you <i>also</i> use the <code>PACKAGE</code> option, <code>Text::Template</code> loads the variables into the package you specified, and they stay there after the call returns. Subsequent calls to <code>fill_in</code> that use the same package will pick up the values you loaded in.</p>

<p>If the argument of <code>HASH</code> is a reference to an array instead of a reference to a hash, then the array should contain a list of hashes whose contents are loaded into the template package one after the other. You can use this feature if you want to combine several sets of variables. For example, one set of variables might be the defaults for a fill-in form, and the second set might be the user inputs, which override the defaults when they are present:</p>

<pre><code>    $template-&gt;fill_in(HASH =&gt; [\%defaults, \%user_input]);</code></pre>

<p>You can also use this to set two variables with the same name:</p>

<pre><code>    $template-&gt;fill_in(
        HASH =&gt; [
            { v =&gt; &quot;The King&quot; },
            { v =&gt; [1,2,3] }
        ]
    );</code></pre>

<p>This sets <code>$v</code> to <code>&quot;The King&quot;</code> and <code>@v</code> to <code>(1,2,3)</code>.</p>

</dd>
<dt id="BROKEN1"><code>BROKEN</code></dt>
<dd>

<p>If any of the program fragments fails to compile or aborts for any reason, and you have set the <code>BROKEN</code> option to a function reference, <code>Text::Template</code> will invoke the function. This function is called the <i><code>BROKEN</code> function</i>. The <code>BROKEN</code> function will tell <code>Text::Template</code> what to do next.</p>

<p>If the <code>BROKEN</code> function returns <code>undef</code>, <code>Text::Template</code> will immediately abort processing the template and return the text that it has accumulated so far. If your function does this, it should set a flag that you can examine after <code>fill_in</code> returns so that you can tell whether there was a premature return or not.</p>

<p>If the <code>BROKEN</code> function returns any other value, that value will be interpolated into the template as if that value had been the return value of the program fragment to begin with. For example, if the <code>BROKEN</code> function returns an error string, the error string will be interpolated into the output of the template in place of the program fragment that cased the error.</p>

<p>If you don&#39;t specify a <code>BROKEN</code> function, <code>Text::Template</code> supplies a default one that returns something like</p>

<pre><code>    Program fragment delivered error ``Illegal division by 0 at
    template line 37&#39;&#39;</code></pre>

<p>(Note that the format of this message has changed slightly since version 1.31.) The return value of the <code>BROKEN</code> function is interpolated into the template at the place the error occurred, so that this template:</p>

<pre><code>    (3+4)*5 = { 3+4)*5 }</code></pre>

<p>yields this result:</p>

<pre><code>    (3+4)*5 = Program fragment delivered error ``syntax error at template line 1&#39;&#39;</code></pre>

<p>If you specify a value for the <code>BROKEN</code> attribute, it should be a reference to a function that <code>fill_in</code> can call instead of the default function.</p>

<p><code>fill_in</code> will pass a hash to the <code>broken</code> function. The hash will have at least these three members:</p>

<dl>

<dt id="text"><code>text</code></dt>
<dd>

<p>The source code of the program fragment that failed</p>

</dd>
<dt id="error"><code>error</code></dt>
<dd>

<p>The text of the error message (<code>$@</code>) generated by eval.</p>

<p>The text has been modified to omit the trailing newline and to include the name of the template file (if there was one). The line number counts from the beginning of the template, not from the beginning of the failed program fragment.</p>

</dd>
<dt id="lineno"><code>lineno</code></dt>
<dd>

<p>The line number of the template at which the program fragment began.</p>

</dd>
</dl>

<p>There may also be an <code>arg</code> member. See <code>BROKEN_ARG</code>, below</p>

</dd>
<dt id="BROKEN_ARG"><code>BROKEN_ARG</code></dt>
<dd>

<p>If you supply the <code>BROKEN_ARG</code> option to <code>fill_in</code>, the value of the option is passed to the <code>BROKEN</code> function whenever it is called. The default <code>BROKEN</code> function ignores the <code>BROKEN_ARG</code>, but you can write a custom <code>BROKEN</code> function that uses the <code>BROKEN_ARG</code> to get more information about what went wrong.</p>

<p>The <code>BROKEN</code> function could also use the <code>BROKEN_ARG</code> as a reference to store an error message or some other information that it wants to communicate back to the caller. For example:</p>

<pre><code>    $error = &#39;&#39;;

    sub my_broken {
       my %args = @_;
       my $err_ref = $args{arg};
       ...
       $$err_ref = &quot;Some error message&quot;;
       return undef;
    }

    $template-&gt;fill_in(
        BROKEN     =&gt; \&amp;my_broken,
        BROKEN_ARG =&gt; \$error
    );

    if ($error) {
      die &quot;It didn&#39;t work: $error&quot;;
    }</code></pre>

<p>If one of the program fragments in the template fails, it will call the <code>BROKEN</code> function, <code>my_broken</code>, and pass it the <code>BROKEN_ARG</code>, which is a reference to <code>$error</code>. <code>my_broken</code> can store an error message into <code>$error</code> this way. Then the function that called <code>fill_in</code> can see if <code>my_broken</code> has left an error message for it to find, and proceed accordingly.</p>

</dd>
<dt id="FILENAME"><code>FILENAME</code></dt>
<dd>

<p>If you give <code>fill_in</code> a <code>FILENAME</code> option, then this is the file name that you loaded the template source from. This only affects the error message that is given for template errors. If you loaded the template from <code>foo.txt</code> for example, and pass <code>foo.txt</code> as the <code>FILENAME</code> parameter, errors will look like <code>... at foo.txt line N</code> rather than <code>... at template line N</code>.</p>

<p>Note that this does NOT have anything to do with loading a template from the given filename. See <code>fill_in_file()</code> for that.</p>

<p>For example:</p>

<pre><code> my $template = Text::Template-&gt;new(
     TYPE   =&gt; &#39;string&#39;,
     SOURCE =&gt; &#39;The value is {1/0}&#39;);

 $template-&gt;fill_in(FILENAME =&gt; &#39;foo.txt&#39;) or die $Text::Template::ERROR;</code></pre>

<p>will die with an error that contains</p>

<pre><code> Illegal division by zero at at foo.txt line 1</code></pre>

</dd>
<dt id="SAFE"><code>SAFE</code></dt>
<dd>

<p>If you give <code>fill_in</code> a <code>SAFE</code> option, its value should be a safe compartment object from the <code>Safe</code> package. All evaluation of program fragments will be performed in this compartment. See <a href="https://metacpan.org/pod/Safe">Safe</a> for full details about such compartments and how to restrict the operations that can be performed in them.</p>

<p>If you use the <code>PACKAGE</code> option with <code>SAFE</code>, the package you specify will be placed into the safe compartment and evaluation will take place in that package as usual.</p>

<p>If not, <code>SAFE</code> operation is a little different from the default. Usually, if you don&#39;t specify a package, evaluation of program fragments occurs in the package from which the template was invoked. But in <code>SAFE</code> mode the evaluation occurs inside the safe compartment and cannot affect the calling package. Normally, if you use <code>HASH</code> without <code>PACKAGE</code>, the hash variables are imported into a private, one-use-only package. But if you use <code>HASH</code> and <code>SAFE</code> together without <code>PACKAGE</code>, the hash variables will just be loaded into the root namespace of the <code>Safe</code> compartment.</p>

</dd>
<dt id="OUTPUT"><code>OUTPUT</code></dt>
<dd>

<p>If your template is going to generate a lot of text that you are just going to print out again anyway, you can save memory by having <code>Text::Template</code> print out the text as it is generated instead of making it into a big string and returning the string. If you supply the <code>OUTPUT</code> option to <code>fill_in</code>, the value should be a filehandle. The generated text will be printed to this filehandle as it is constructed. For example:</p>

<pre><code>    $template-&gt;fill_in(OUTPUT =&gt; \*STDOUT, ...);</code></pre>

<p>fills in the <code>$template</code> as usual, but the results are immediately printed to STDOUT. This may result in the output appearing more quickly than it would have otherwise.</p>

<p>If you use <code>OUTPUT</code>, the return value from <code>fill_in</code> is still true on success and false on failure, but the complete text is not returned to the caller.</p>

</dd>
<dt id="PREPEND1"><code>PREPEND</code></dt>
<dd>

<p>You can have some Perl code prepended automatically to the beginning of every program fragment. See <a href="./Text::Template.html#PREPEND-feature-and-using-strict-in-templates">&quot;<code>PREPEND</code> feature and using <code>strict</code> in templates&quot;</a> below.</p>

</dd>
<dt id="DELIMITERS1"><code>DELIMITERS</code></dt>
<dd>

<p>If this option is present, its value should be a reference to a list of two strings. The first string is the string that signals the beginning of each program fragment, and the second string is the string that signals the end of each program fragment. See <a href="./Text::Template.html#Alternative-Delimiters">&quot;Alternative Delimiters&quot;</a>, below.</p>

<p>If you specify <code>DELIMITERS</code> in the call to <code>fill_in</code>, they override any delimiters you set when you created the template object with <code>new</code>.</p>

</dd>
</dl>

<h1 id="Convenience-Functions"><a id="Convenience"></a>Convenience Functions</h1>

<h2 id="fill_this_in"><code>fill_this_in</code></h2>

<p>The basic way to fill in a template is to create a template object and then call <code>fill_in</code> on it. This is useful if you want to fill in the same template more than once.</p>

<p>In some programs, this can be cumbersome. <code>fill_this_in</code> accepts a string, which contains the template, and a list of options, which are passed to <code>fill_in</code> as above. It constructs the template object for you, fills it in as specified, and returns the results. It returns <code>undef</code> and sets <code>$Text::Template::ERROR</code> if it couldn&#39;t generate any results.</p>

<p>An example:</p>

<pre><code>    $Q::name = &#39;Donald&#39;;
    $Q::amount = 141.61;
    $Q::part = &#39;hyoid bone&#39;;

    $text = Text::Template-&gt;fill_this_in( &lt;&lt;&#39;EOM&#39;, PACKAGE =&gt; Q);
    Dear {$name},
    You owe me \\${sprintf(&#39;%.2f&#39;, $amount)}.
    Pay or I will break your {$part}.
        Love,
        Grand Vizopteryx of Irkutsk.
    EOM</code></pre>

<p>Notice how we included the template in-line in the program by using a `here document&#39; with the <code>&lt;&lt;</code> notation.</p>

<p><code>fill_this_in</code> is a deprecated feature. It is only here for backwards compatibility, and may be removed in some far-future version in <code>Text::Template</code>. You should use <code>fill_in_string</code> instead. It is described in the next section.</p>

<h2 id="fill_in_string"><code>fill_in_string</code></h2>

<p>It is stupid that <code>fill_this_in</code> is a class method. It should have been just an imported function, so that you could omit the <code>Text::Template-&gt;</code> in the example above. But I made the mistake four years ago and it is too late to change it.</p>

<p><code>fill_in_string</code> is exactly like <code>fill_this_in</code> except that it is not a method and you can omit the <code>Text::Template-&gt;</code> and just say</p>

<pre><code>    print fill_in_string(&lt;&lt;&#39;EOM&#39;, ...);
    Dear {$name},
      ...
    EOM</code></pre>

<p>To use <code>fill_in_string</code>, you need to say</p>

<pre><code>    use Text::Template &#39;fill_in_string&#39;;</code></pre>

<p>at the top of your program. You should probably use <code>fill_in_string</code> instead of <code>fill_this_in</code>.</p>

<h2 id="fill_in_file"><code>fill_in_file</code></h2>

<p>If you import <code>fill_in_file</code>, you can say</p>

<pre><code>    $text = fill_in_file(filename, ...);</code></pre>

<p>The <code>...</code> are passed to <code>fill_in</code> as above. The filename is the name of the file that contains the template you want to fill in. It returns the result text. or <code>undef</code>, as usual.</p>

<p>If you are going to fill in the same file more than once in the same program you should use the longer <code>new</code> / <code>fill_in</code> sequence instead. It will be a lot faster because it only has to read and parse the file once.</p>

<h2 id="Including-files-into-templates"><a id="Including"></a>Including files into templates</h2>

<p>People always ask for this. ``Why don&#39;t you have an include function?&#39;&#39; they want to know. The short answer is this is Perl, and Perl already has an include function. If you want it, you can just put</p>

<pre><code>    {qx{cat filename}}</code></pre>

<p>into your template. Voil&agrave;.</p>

<p>If you don&#39;t want to use <code>cat</code>, you can write a little four-line function that opens a file and dumps out its contents, and call it from the template. I wrote one for you. In the template, you can say</p>

<pre><code>    {Text::Template::_load_text(filename)}</code></pre>

<p>If that is too verbose, here is a trick. Suppose the template package that you are going to be mentioning in the <code>fill_in</code> call is package <code>Q</code>. Then in the main program, write</p>

<pre><code>    *Q::include = \&amp;Text::Template::_load_text;</code></pre>

<p>This imports the <code>_load_text</code> function into package <code>Q</code> with the name <code>include</code>. From then on, any template that you fill in with package <code>Q</code> can say</p>

<pre><code>    {include(filename)}</code></pre>

<p>to insert the text from the named file at that point. If you are using the <code>HASH</code> option instead, just put <code>include =&gt; \&amp;Text::Template::_load_text</code> into the hash instead of importing it explicitly.</p>

<p>Suppose you don&#39;t want to insert a plain text file, but rather you want to include one template within another? Just use <code>fill_in_file</code> in the template itself:</p>

<pre><code>    {Text::Template::fill_in_file(filename)}</code></pre>

<p>You can do the same importing trick if this is too much to type.</p>

<h1 id="Miscellaneous">Miscellaneous</h1>

<h2 id="my-variables"><a id="my"></a><code>my</code> variables</h2>

<p>People are frequently surprised when this doesn&#39;t work:</p>

<pre><code>    my $recipient = &#39;The King&#39;;
    my $text = fill_in_file(&#39;formletter.tmpl&#39;);</code></pre>

<p>The text <code>The King</code> doesn&#39;t get into the form letter. Why not? Because <code>$recipient</code> is a <code>my</code> variable, and the whole point of <code>my</code> variables is that they&#39;re private and inaccessible except in the scope in which they&#39;re declared. The template is not part of that scope, so the template can&#39;t see <code>$recipient</code>.</p>

<p>If that&#39;s not the behavior you want, don&#39;t use <code>my</code>. <code>my</code> means a private variable, and in this case you don&#39;t want the variable to be private. Put the variables into package variables in some other package, and use the <code>PACKAGE</code> option to <code>fill_in</code>:</p>

<pre><code>    $Q::recipient = $recipient;
    my $text = fill_in_file(&#39;formletter.tmpl&#39;, PACKAGE =&gt; &#39;Q&#39;);</code></pre>

<p>or pass the names and values in a hash with the <code>HASH</code> option:</p>

<pre><code>    my $text = fill_in_file(&#39;formletter.tmpl&#39;, HASH =&gt; { recipient =&gt; $recipient });</code></pre>

<h2 id="Security-Matters"><a id="Security"></a>Security Matters</h2>

<p>All variables are evaluated in the package you specify with the <code>PACKAGE</code> option of <code>fill_in</code>. if you use this option, and if your templates don&#39;t do anything egregiously stupid, you won&#39;t have to worry that evaluation of the little programs will creep out into the rest of your program and wreck something.</p>

<p>Nevertheless, there&#39;s really no way (except with <code>Safe</code>) to protect against a template that says</p>

<pre><code>    { $Important::Secret::Security::Enable = 0;
      # Disable security checks in this program
    }</code></pre>

<p>or</p>

<pre><code>    { $/ = &quot;ho ho ho&quot;;   # Sabotage future uses of &lt;FH&gt;.
      # $/ is always a global variable
    }</code></pre>

<p>or even</p>

<pre><code>    { system(&quot;rm -rf /&quot;) }</code></pre>

<p>so <b>don&#39;t</b> go filling in templates unless you&#39;re sure you know what&#39;s in them. If you&#39;re worried, or you can&#39;t trust the person who wrote the template, use the <code>SAFE</code> option.</p>

<p>A final warning: program fragments run a small risk of accidentally clobbering local variables in the <code>fill_in</code> function itself. These variables all have names that begin with <code>$fi_</code>, so if you stay away from those names you&#39;ll be safe. (Of course, if you&#39;re a real wizard you can tamper with them deliberately for exciting effects; this is actually how <code>$OUT</code> works.) I can fix this, but it will make the package slower to do it, so I would prefer not to. If you are worried about this, send me mail and I will show you what to do about it.</p>

<h2 id="Alternative-Delimiters"><a id="Alternative"></a>Alternative Delimiters</h2>

<p>Lorenzo Valdettaro pointed out that if you are using <code>Text::Template</code> to generate TeX output, the choice of braces as the program fragment delimiters makes you suffer suffer suffer. Starting in version 1.20, you can change the choice of delimiters to something other than curly braces.</p>

<p>In either the <code>new()</code> call or the <code>fill_in()</code> call, you can specify an alternative set of delimiters with the <code>DELIMITERS</code> option. For example, if you would like code fragments to be delimited by <code>[@--</code> and <code>--@]</code> instead of <code>{</code> and <code>}</code>, use</p>

<pre><code>    ... DELIMITERS =&gt; [ &#39;[@--&#39;, &#39;--@]&#39; ], ...</code></pre>

<p>Note that these delimiters are <i>literal strings</i>, not regexes. (I tried for regexes, but it complicates the lexical analysis too much.) Note also that <code>DELIMITERS</code> disables the special meaning of the backslash, so if you want to include the delimiters in the literal text of your template file, you are out of luck---it is up to you to choose delimiters that do not conflict with what you are doing. The delimiter strings may still appear inside of program fragments as long as they nest properly. This means that if for some reason you absolutely must have a program fragment that mentions one of the delimiters, like this:</p>

<pre><code>    [@--
        print &quot;Oh no, a delimiter: --@]\n&quot;
    --@]</code></pre>

<p>you may be able to make it work by doing this instead:</p>

<pre><code>    [@--
        # Fake matching delimiter in a comment: [@--
        print &quot;Oh no, a delimiter: --@]\n&quot;
    --@]</code></pre>

<p>It may be safer to choose delimiters that begin with a newline character.</p>

<p>Because the parsing of templates is simplified by the absence of backslash escapes, using alternative <code>DELIMITERS</code> may speed up the parsing process by 20-25%. This shows that my original choice of <code>{</code> and <code>}</code> was very bad.</p>

<h2 id="PREPEND-feature-and-using-strict-in-templates"><a id="PREPEND2"></a><code>PREPEND</code> feature and using <code>strict</code> in templates</h2>

<p>Suppose you would like to use <code>strict</code> in your templates to detect undeclared variables and the like. But each code fragment is a separate lexical scope, so you have to turn on <code>strict</code> at the top of each and every code fragment:</p>

<pre><code>    { use strict;
      use vars &#39;$foo&#39;;
      $foo = 14;
      ...
    }

    ...

    { # we forgot to put `use strict&#39; here
      my $result = $boo + 12;    # $boo is misspelled and should be $foo
      # No error is raised on `$boo&#39;
    }</code></pre>

<p>Because we didn&#39;t put <code>use strict</code> at the top of the second fragment, it was only active in the first fragment, and we didn&#39;t get any <code>strict</code> checking in the second fragment. Then we misspelled <code>$foo</code> and the error wasn&#39;t caught.</p>

<p><code>Text::Template</code> version 1.22 and higher has a new feature to make this easier. You can specify that any text at all be automatically added to the beginning of each program fragment.</p>

<p>When you make a call to <code>fill_in</code>, you can specify a</p>

<pre><code>    PREPEND =&gt; &#39;some perl statements here&#39;</code></pre>

<p>option; the statements will be prepended to each program fragment for that one call only. Suppose that the <code>fill_in</code> call included a</p>

<pre><code>    PREPEND =&gt; &#39;use strict;&#39;</code></pre>

<p>option, and that the template looked like this:</p>

<pre><code>    { use vars &#39;$foo&#39;;
      $foo = 14;
      ...
    }

    ...

    { my $result = $boo + 12;    # $boo is misspelled and should be $foo
      ...
    }</code></pre>

<p>The code in the second fragment would fail, because <code>$boo</code> has not been declared. <code>use strict</code> was implied, even though you did not write it explicitly, because the <code>PREPEND</code> option added it for you automatically.</p>

<p>There are three other ways to do this. At the time you create the template object with <code>new</code>, you can also supply a <code>PREPEND</code> option, in which case the statements will be prepended each time you fill in that template. If the <code>fill_in</code> call has its own <code>PREPEND</code> option, this overrides the one specified at the time you created the template. Finally, you can make the class method call</p>

<pre><code>    Text::Template-&gt;always_prepend(&#39;perl statements&#39;);</code></pre>

<p>If you do this, then call calls to <code>fill_in</code> for <i>any</i> template will attach the perl statements to the beginning of each program fragment, except where overridden by <code>PREPEND</code> options to <code>new</code> or <code>fill_in</code>.</p>

<p>An alternative to adding &quot;use strict;&quot; to the PREPEND option, you can pass STRICT =&gt; 1 to fill_in when also passing the HASH option.</p>

<p>Suppose that the <code>fill_in</code> call included both</p>

<pre><code>    HASH   =&gt; {$foo =&gt; &#39;&#39;} and
    STRICT =&gt; 1</code></pre>

<p>options, and that the template looked like this:</p>

<pre><code>    {
      $foo = 14;
      ...
    }

    ...

    { my $result = $boo + 12;    # $boo is misspelled and should be $foo
      ...
    }</code></pre>

<p>The code in the second fragment would fail, because <code>$boo</code> has not been declared. <code>use strict</code> was implied, even though you did not write it explicitly, because the <code>STRICT</code> option added it for you automatically. Any variable referenced in the template that is not in the <code>HASH</code> option will be an error.</p>

<h2 id="Prepending-in-Derived-Classes"><a id="Prepending"></a>Prepending in Derived Classes</h2>

<p>This section is technical, and you should skip it on the first few readings.</p>

<p>Normally there are three places that prepended text could come from. It could come from the <code>PREPEND</code> option in the <code>fill_in</code> call, from the <code>PREPEND</code> option in the <code>new</code> call that created the template object, or from the argument of the <code>always_prepend</code> call. <code>Text::Template</code> looks for these three things in order and takes the first one that it finds.</p>

<p>In a subclass of <code>Text::Template</code>, this last possibility is ambiguous. Suppose <code>S</code> is a subclass of <code>Text::Template</code>. Should</p>

<pre><code>    Text::Template-&gt;always_prepend(...);</code></pre>

<p>affect objects in class <code>Derived</code>? The answer is that you can have it either way.</p>

<p>The <code>always_prepend</code> value for <code>Text::Template</code> is normally stored in a hash variable named <code>%GLOBAL_PREPEND</code> under the key <code>Text::Template</code>. When <code>Text::Template</code> looks to see what text to prepend, it first looks in the template object itself, and if not, it looks in <code>$GLOBAL_PREPEND{<i>class</i>}</code> where <i>class</i> is the class to which the template object belongs. If it doesn&#39;t find any value, it looks in <code>$GLOBAL_PREPEND{&#39;Text::Template&#39;}</code>. This means that objects in class <code>Derived</code> <i>will</i> be affected by</p>

<pre><code>    Text::Template-&gt;always_prepend(...);</code></pre>

<p><i>unless</i> there is also a call to</p>

<pre><code>    Derived-&gt;always_prepend(...);</code></pre>

<p>So when you&#39;re designing your derived class, you can arrange to have your objects ignore <code>Text::Template::always_prepend</code> calls by simply putting <code>Derived-&gt;always_prepend(&#39;&#39;)</code> at the top of your module.</p>

<p>Of course, there is also a final escape hatch: Templates support a <code>prepend_text</code> that is used to look up the appropriate text to be prepended at <code>fill_in</code> time. Your derived class can override this method to get an arbitrary effect.</p>

<h2 id="JavaScript">JavaScript</h2>

<p>Jennifer D. St Clair asks:</p>

<pre><code>    &gt; Most of my pages contain JavaScript and Stylesheets.
    &gt; How do I change the template identifier?</code></pre>

<p>Jennifer is worried about the braces in the JavaScript being taken as the delimiters of the Perl program fragments. Of course, disaster will ensue when perl tries to evaluate these as if they were Perl programs. The best choice is to find some unambiguous delimiter strings that you can use in your template instead of curly braces, and then use the <code>DELIMITERS</code> option. However, if you can&#39;t do this for some reason, there are two easy workarounds:</p>

<p>1. You can put <code>\</code> in front of <code>{</code>, <code>}</code>, or <code>\</code> to remove its special meaning. So, for example, instead of</p>

<pre><code>    if (br== &quot;n3&quot;) { 
        // etc.
    }</code></pre>

<p>you can put</p>

<pre><code>    if (br== &quot;n3&quot;) \{
        // etc.
    \}</code></pre>

<p>and it&#39;ll come out of the template engine the way you want.</p>

<p>But here is another method that is probably better. To see how it works, first consider what happens if you put this into a template:</p>

<pre><code>    { &#39;foo&#39; }</code></pre>

<p>Since it&#39;s in braces, it gets evaluated, and obviously, this is going to turn into</p>

<pre><code>    foo</code></pre>

<p>So now here&#39;s the trick: In Perl, <code>q{...}</code> is the same as <code>&#39;...&#39;</code>. So if we wrote</p>

<pre><code>    {q{foo}}</code></pre>

<p>it would turn into</p>

<pre><code>    foo</code></pre>

<p>So for your JavaScript, just write</p>

<pre><code>    {q{if (br== &quot;n3&quot;) {
       // etc.
       }}
    }</code></pre>

<p>and it&#39;ll come out as</p>

<pre><code>    if (br== &quot;n3&quot;) {
        // etc.
    }</code></pre>

<p>which is what you want.</p>

<p>head2 Shut Up!</p>

<p>People sometimes try to put an initialization section at the top of their templates, like this:</p>

<pre><code>    { ...
        $var = 17;
    }</code></pre>

<p>Then they complain because there is a <code>17</code> at the top of the output that they didn&#39;t want to have there.</p>

<p>Remember that a program fragment is replaced with its own return value, and that in Perl the return value of a code block is the value of the last expression that was evaluated, which in this case is 17. If it didn&#39;t do that, you wouldn&#39;t be able to write <code>{$recipient}</code> and have the recipient filled in.</p>

<p>To prevent the 17 from appearing in the output is very simple:</p>

<pre><code>    { ...
        $var = 17;
        &#39;&#39;;
    }</code></pre>

<p>Now the last expression evaluated yields the empty string, which is invisible. If you don&#39;t like the way this looks, use</p>

<pre><code>    { ...
        $var = 17;
        ($SILENTLY);
    }</code></pre>

<p>instead. Presumably, <code>$SILENTLY</code> has no value, so nothing will be interpolated. This is what is known as a `trick&#39;.</p>

<h2 id="Compatibility">Compatibility</h2>

<p>Every effort has been made to make this module compatible with older versions. The only known exceptions follow:</p>

<p>The output format of the default <code>BROKEN</code> subroutine has changed twice, most recently between versions 1.31 and 1.40.</p>

<p>Starting in version 1.10, the <code>$OUT</code> variable is arrogated for a special meaning. If you had templates before version 1.10 that happened to use a variable named <code>$OUT</code>, you will have to change them to use some other variable or all sorts of strangeness will result.</p>

<p>Between versions 0.1b and 1.00 the behavior of the \ metacharacter changed. In 0.1b, \\ was special everywhere, and the template processor always replaced it with a single backslash before passing the code to Perl for evaluation. The rule now is more complicated but probably more convenient. See the section on backslash processing, below, for a full discussion.</p>

<h2 id="Backslash-Processing"><a id="Backslash"></a>Backslash Processing</h2>

<p>In <code>Text::Template</code> beta versions, the backslash was special whenever it appeared before a brace or another backslash. That meant that while <code>{&quot;\n&quot;}</code> did indeed generate a newline, <code>{&quot;\\&quot;}</code> did not generate a backslash, because the code passed to Perl for evaluation was <code>&quot;\&quot;</code> which is a syntax error. If you wanted a backslash, you would have had to write <code>{&quot;\\\\&quot;}</code>.</p>

<p>In <code>Text::Template</code> versions 1.00 through 1.10, there was a bug: Backslash was special everywhere. In these versions, <code>{&quot;\n&quot;}</code> generated the letter <code>n</code>.</p>

<p>The bug has been corrected in version 1.11, but I did not go back to exactly the old rule, because I did not like the idea of having to write <code>{&quot;\\\\&quot;}</code> to get one backslash. The rule is now more complicated to remember, but probably easier to use. The rule is now: Backslashes are always passed to Perl unchanged <i>unless</i> they occur as part of a sequence like <code>\\\\\\{</code> or <code>\\\\\\}</code>. In these contexts, they are special; <code>\\</code> is replaced with <code>\</code>, and <code>\{</code> and <code>\}</code> signal a literal brace.</p>

<p>Examples:</p>

<pre><code>    \{ foo \}</code></pre>

<p>is <i>not</i> evaluated, because the <code>\</code> before the braces signals that they should be taken literally. The result in the output looks like this:</p>

<pre><code>    { foo }</code></pre>

<p>This is a syntax error:</p>

<pre><code>    { &quot;foo}&quot; }</code></pre>

<p>because <code>Text::Template</code> thinks that the code ends at the first <code>}</code>, and then gets upset when it sees the second one. To make this work correctly, use</p>

<pre><code>    { &quot;foo\}&quot; }</code></pre>

<p>This passes <code>&quot;foo}&quot;</code> to Perl for evaluation. Note there&#39;s no <code>\</code> in the evaluated code. If you really want a <code>\</code> in the evaluated code, use</p>

<pre><code>    { &quot;foo\\\}&quot; }</code></pre>

<p>This passes <code>&quot;foo\}&quot;</code> to Perl for evaluation.</p>

<p>Starting with <code>Text::Template</code> version 1.20, backslash processing is disabled if you use the <code>DELIMITERS</code> option to specify alternative delimiter strings.</p>

<h2 id="A-short-note-about-$Text::Template::ERROR"><a id="A"></a><a id="A-short-note-about--Text::Template::ERROR"></a>A short note about <code>$Text::Template::ERROR</code></h2>

<p>In the past some people have fretted about `violating the package boundary&#39; by examining a variable inside the <code>Text::Template</code> package. Don&#39;t feel this way. <code>$Text::Template::ERROR</code> is part of the published, official interface to this package. It is perfectly OK to inspect this variable. The interface is not going to change.</p>

<p>If it really, really bothers you, you can import a function called <code>TTerror</code> that returns the current value of the <code>$ERROR</code> variable. So you can say:</p>

<pre><code>    use Text::Template &#39;TTerror&#39;;

    my $template = Text::Template-&gt;new(SOURCE =&gt; $filename);
    unless ($template) {
        my $err = TTerror;
        die &quot;Couldn&#39;t make template: $err; aborting&quot;;
    }</code></pre>

<p>I don&#39;t see what benefit this has over just doing this:</p>

<pre><code>    use Text::Template;

    my $template = Text::Template-&gt;new(SOURCE =&gt; $filename)
        or die &quot;Couldn&#39;t make template: $Text::Template::ERROR; aborting&quot;;</code></pre>

<p>But if it makes you happy to do it that way, go ahead.</p>

<h2 id="Sticky-Widgets-in-Template-Files"><a id="Sticky"></a>Sticky Widgets in Template Files</h2>

<p>The <code>CGI</code> module provides functions for `sticky widgets&#39;, which are form input controls that retain their values from one page to the next. Sometimes people want to know how to include these widgets into their template output.</p>

<p>It&#39;s totally straightforward. Just call the <code>CGI</code> functions from inside the template:</p>

<pre><code>    { $q-&gt;checkbox_group(NAME      =&gt; &#39;toppings&#39;,
                         LINEBREAK =&gt; true,
                         COLUMNS   =&gt; 3,
                         VALUES    =&gt; \@toppings,
                        );
    }</code></pre>

<h2 id="Automatic-preprocessing-of-program-fragments"><a id="Automatic"></a>Automatic preprocessing of program fragments</h2>

<p>It may be useful to preprocess the program fragments before they are evaluated. See <code>Text::Template::Preprocess</code> for more details.</p>

<h2 id="Automatic-postprocessing-of-template-hunks"><a id="Automatic1"></a>Automatic postprocessing of template hunks</h2>

<p>It may be useful to process hunks of output before they are appended to the result text. For this, subclass and replace the <code>append_text_to_result</code> method. It is passed a list of pairs with these entries:</p>

<pre><code>  handle - a filehandle to which to print the desired output
  out    - a ref to a string to which to append, to use if handle is not given
  text   - the text that will be appended
  type   - where the text came from: TEXT for literal text, PROG for code</code></pre>

<h1 id="HISTORY">HISTORY</h1>

<p>Originally written by Mark Jason Dominus, Plover Systems (versions 0.01 - 1.46)</p>

<p>Maintainership transferred to Michael Schout &lt;mschout@cpan.org&gt; in version 1.47</p>

<h1 id="THANKS">THANKS</h1>

<p>Many thanks to the following people for offering support, encouragement, advice, bug reports, and all the other good stuff.</p>

<ul>

<li><p>Andrew G Wood</p>

</li>
<li><p>Andy Wardley</p>

</li>
<li><p>Ant&oacute;nio Arag&atilde;o</p>

</li>
<li><p>Archie Warnock</p>

</li>
<li><p>Bek Oberin</p>

</li>
<li><p>Bob Dougherty</p>

</li>
<li><p>Brian C. Shensky</p>

</li>
<li><p>Chris Nandor</p>

</li>
<li><p>Chris Wesley</p>

</li>
<li><p>Chris.Brezil</p>

</li>
<li><p>Daini Xie</p>

</li>
<li><p>Dan Franklin</p>

</li>
<li><p>Daniel LaLiberte</p>

</li>
<li><p>David H. Adler</p>

</li>
<li><p>David Marshall</p>

</li>
<li><p>Dennis Taylor</p>

</li>
<li><p>Donald L. Greer Jr.</p>

</li>
<li><p>Dr. Frank Bucolo</p>

</li>
<li><p>Fred Steinberg</p>

</li>
<li><p>Gene Damon</p>

</li>
<li><p>Hans Persson</p>

</li>
<li><p>Hans Stoop</p>

</li>
<li><p>Itamar Almeida de Carvalho</p>

</li>
<li><p>James H. Thompson</p>

</li>
<li><p>James Mastros</p>

</li>
<li><p>Jarko Hietaniemi</p>

</li>
<li><p>Jason Moore</p>

</li>
<li><p>Jennifer D. St Clair</p>

</li>
<li><p>Joel Appelbaum</p>

</li>
<li><p>Joel Meulenberg</p>

</li>
<li><p>Jonathan Roy</p>

</li>
<li><p>Joseph Cheek</p>

</li>
<li><p>Juan E. Camacho</p>

</li>
<li><p>Kevin Atteson</p>

</li>
<li><p>Kevin Madsen</p>

</li>
<li><p>Klaus Arnhold</p>

</li>
<li><p>Larry Virden</p>

</li>
<li><p>Lieven Tomme</p>

</li>
<li><p>Lorenzo Valdettaro</p>

</li>
<li><p>Marek Grac</p>

</li>
<li><p>Matt Womer</p>

</li>
<li><p>Matt X. Hunter</p>

</li>
<li><p>Michael G Schwern</p>

</li>
<li><p>Michael J. Suzio</p>

</li>
<li><p>Michaely Yeung</p>

</li>
<li><p>Michelangelo Grigni</p>

</li>
<li><p>Mike Brodhead</p>

</li>
<li><p>Niklas Skoglund</p>

</li>
<li><p>Randal L. Schwartz</p>

</li>
<li><p>Reuven M. Lerner</p>

</li>
<li><p>Robert M. Ioffe</p>

</li>
<li><p>Ron Pero</p>

</li>
<li><p>San Deng</p>

</li>
<li><p>Sean Roehnelt</p>

</li>
<li><p>Sergey Myasnikov</p>

</li>
<li><p>Shabbir J. Safdar</p>

</li>
<li><p>Shad Todd</p>

</li>
<li><p>Steve Palincsar</p>

</li>
<li><p>Tim Bunce</p>

</li>
<li><p>Todd A. Green</p>

</li>
<li><p>Tom Brown</p>

</li>
<li><p>Tom Henry</p>

</li>
<li><p>Tom Snee</p>

</li>
<li><p>Trip Lilley</p>

</li>
<li><p>Uwe Schneider</p>

</li>
<li><p>Val Luck</p>

</li>
<li><p>Yannis Livassof</p>

</li>
<li><p>Yonat Sharon</p>

</li>
<li><p>Zac Hansen</p>

</li>
<li><p>gary at dls.net</p>

</li>
</ul>

<p>Special thanks to:</p>

<dl>

<dt id="Jonathan-Roy"><a id="Jonathan"></a>Jonathan Roy</dt>
<dd>

<p>for telling me how to do the <code>Safe</code> support (I spent two years worrying about it, and then Jonathan pointed out that it was trivial.)</p>

</dd>
<dt id="Ranjit-Bhatnagar"><a id="Ranjit"></a>Ranjit Bhatnagar</dt>
<dd>

<p>for demanding less verbose fragments like they have in ASP, for helping me figure out the Right Thing, and, especially, for talking me out of adding any new syntax. These discussions resulted in the <code>$OUT</code> feature.</p>

</dd>
</dl>

<h2 id="Bugs-and-Caveats"><a id="Bugs"></a>Bugs and Caveats</h2>

<p><code>my</code> variables in <code>fill_in</code> are still susceptible to being clobbered by template evaluation. They all begin with <code>fi_</code>, so avoid those names in your templates.</p>

<p>The line number information will be wrong if the template&#39;s lines are not terminated by <code>&quot;\n&quot;</code>. You should let me know if this is a problem. If you do, I will fix it.</p>

<p>The <code>$OUT</code> variable has a special meaning in templates, so you cannot use it as if it were a regular variable.</p>

<p>There are not quite enough tests in the test suite.</p>

<h1 id="SOURCE">SOURCE</h1>

<p>The development version is on github at <a href="https://https://github.com/mschout/perl-text-template">https://https://github.com/mschout/perl-text-template</a> and may be cloned from <a>git://https://github.com/mschout/perl-text-template.git</a></p>

<h1 id="BUGS">BUGS</h1>

<p>Please report any bugs or feature requests on the bugtracker website <a href="https://github.com/mschout/perl-text-template/issues">https://github.com/mschout/perl-text-template/issues</a></p>

<p>When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Michael Schout &lt;mschout@cpan.org&gt;</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>This software is copyright (c) 2013 by Mark Jason Dominus &lt;mjd@cpan.org&gt;.</p>

<p>This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Text::Template, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Text::Template</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Text::Template</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Text::Template.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
